home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3188 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.6 KB

  1. Path: wagner.spc.videotron.ca!news
  2. From: bibcegep@granby.mtl.net (Daniel Marquis)
  3. Newsgroups: comp.lang.c++,comp.lang.c
  4. Subject: Re: getch() equivalency help ...
  5. Date: Mon, 22 Jan 1996 17:45:01 GMT
  6. Organization: SPC
  7. Message-ID: <4e0f3j$9cm@wagner.spc.videotron.ca>
  8. References: <4dpe6p$e4j@twin.wasatch.com>
  9. Reply-To: bibcegep@granby.mtl.net
  10. NNTP-Posting-Host: ttyc1.granby.mtl.net
  11. X-Newsreader: Forte Free Agent 1.0.82
  12.  
  13. >I am looking for help with the following question/problem:
  14.  
  15. >I want to have a function that does the same thing as getch() from
  16. >conio.h, but without needing to include conio.h.
  17.  
  18. >This is for a program that will be compiled across about 5 different 
  19. >platforms, and the only one that supports conio.h is MS-DOS.
  20.  
  21. >I know a similar function is available in UNIX with the ncurses library,
  22. >but I don't have that on my UNIX box ...
  23.  
  24. >I need a way to do what getch() does, i.e. pause and wait for a SINGLE
  25. >KEYSTROKE and then pass the value of the pressed key back to the calling
  26. >function.
  27.  
  28. >For example:
  29.  
  30. >    char incoming=getch();
  31.  
  32. >will pause the program until a single key is pressed and feed the value of 
  33. >that key to the char variable incoming.
  34.  
  35. >I would most optimally like to be able to do this using only what's in 
  36. >iostream.h or stdio.h, whose functions and operators behave alike across all 
  37. >of my target platforms.
  38.  
  39. >I have tried the following:
  40.  
  41. >    char incoming=cin.get();
  42.  
  43. >This pauses the program, but allows an entire line to be entered, terminated
  44. >by a newline, and then only the first character of the line is fed to 
  45. >incoming, and the rest of the line is available to the next input operation
  46. >on the input stream.
  47.  
  48. >The other version of cin.get() does the same thing:
  49. >    
  50. >    cin.get(incoming);
  51.  
  52. >I have tried other functions from stdio.h that have the same result as above.
  53.  
  54. >    char incoming=getchar();
  55. >    char incoming=fgetc(stdin);
  56.  
  57. >I can't seem to find a way to get just a single keystroke in and then flush
  58. >the buffer ...
  59.  
  60. >The only way I have been able to get the behaviour I want is with getch(), and
  61. >it isn't supported on the other target platforms.
  62.  
  63. >If anyone can help, I thank you in advance.
  64.  
  65. >RichD
  66. >rdemanow@wasatch.com
  67. >rjd9404@wcslc.edu
  68.  
  69. >-- 
  70. >rdemanow@wasatch.com           |I am lost.  I have gone to look for
  71. >                               |myself.
  72. >press any key to continue ...  |If I should return before I get back,
  73. >press any other key to quit ...|please ask me to wait here.
  74. I don't really know how in C but you can do it by calling the good
  75. interrupt.  I dont remember the number... I you don't know witch and
  76. how reply at martinclaude@citenet.net or mclaude@citenet.net (I'm
  77. changing my address soon...)
  78.  
  79.  
  80.  
  81.